/**
 * created by 小卷毛, 2021-06-09
 * Copyright (c) 2021, 416143467@qq.com All Rights Reserved.
 * #                   *********                            #
 * #                  ************                          #
 * #                  *************                         #
 * #                 **  ***********                        #
 * #                ***  ****** *****                       #
 * #                *** *******   ****                      #
 * #               ***  ********** ****                     #
 * #              ****  *********** ****                    #
 * #            *****   ***********  *****                  #
 * #           ******   *** ********   *****                #
 * #           *****   ***   ********   ******              #
 * #          ******   ***  ***********   ******            #
 * #         ******   **** **************  ******           #
 * #        *******  ********************* *******          #
 * #        *******  ******************************         #
 * #       *******  ****** ***************** *******        #
 * #       *******  ****** ****** *********   ******        #
 * #       *******    **  ******   ******     ******        #
 * #       *******        ******    *****     *****         #
 * #        ******        *****     *****     ****          #
 * #         *****        ****      *****     ***           #
 * #          *****       ***        ***      *             #
 * #            **       ****        ****                   #
 */
package com.tim.library.third

import android.content.Context
import com.tencent.qcloud.tim.tuiofflinepush.utils.TUIOfflinePushLog
import com.xiaomi.mipush.sdk.*

/**
 * 描 述：
 * 作 者：小卷毛  2021-06-09 10:30
 * 修改描述：
 * 修 改 人：
 * 修改版本：
 */
class XiaomiMsgReceiver : PushMessageReceiver() {

    private val mTAG = this::class.java.simpleName

    override fun onReceivePassThroughMessage(context: Context?, miPushMessage: MiPushMessage?) {
        TUIOfflinePushLog.i(mTAG, "onReceivePassThroughMessage is called.")
    }

    override fun onNotificationMessageClicked(context: Context?, miPushMessage: MiPushMessage?) {
        TUIOfflinePushLog.i(mTAG, "onNotificationMessageClicked is called.")
    }

    override fun onNotificationMessageArrived(context: Context?, miPushMessage: MiPushMessage?) {
        TUIOfflinePushLog.i(mTAG, "onNotificationMessageArrived is called.")
    }

    override fun onReceiveRegisterResult(context: Context?, miPushMessage: MiPushCommandMessage?) {
        TUIOfflinePushLog.i(mTAG, "onReceiveRegisterResult is called.")

        miPushMessage?.let {
            if (MiPushClient.COMMAND_REGISTER == it.command
                && it.resultCode == 0L
            ) {
                val arguments: List<String> = it.commandArguments
                val mRegId = if (arguments.isNotEmpty()) arguments[0] else null

                ThirdPushTokenManager.getInstance().thirdPushToken = mRegId
                ThirdPushTokenManager.getInstance().setPushTokenToTIM()
            }
        }
    }

}